package com.yingsheng.bi.hks.repository.dao.service;

import com.yingsheng.bi.hks.basic.utils.Utils;
import com.yingsheng.bi.hks.repository.dao.mapper.InvoicesMapper;
import com.yingsheng.bi.hks.repository.dao.po.Invoices;
import com.yingsheng.bi.hks.repository.dao.po.InvoicesExample;
import com.yingsheng.bi.hks.repository.dao.po.JobInfoExample;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * invoices表的数据库操作服务
 * 要求说明：
 * 1.一般情况下,要求参数不超过5个时方法入参逐个声明
 * 2.一般情况下,要求条件不超过3个时要在方法名上体现
 * 3.最好对方法入参做一定校验,尤其是对条件参数至少要做非空校验
 *
 * @author 83686
 */
@Repository
public class InvoicesDaoService implements DaoService  {

    @Autowired
    private InvoicesMapper invoicesMapper;

    public boolean insert(Invoices invoices) {
        invoices.setId(Utils.genUUid());
        int result = invoicesMapper.insert(invoices);
        return result == 1;
    }

    public List<Invoices> invoicesPersonQry(Invoices invoices){
        InvoicesExample example = new InvoicesExample();
        InvoicesExample.Criteria criteria = example.createCriteria();
        if (!StringUtil.isNullOrEmpty(invoices.getUserId())){
            criteria.andUserIdEqualTo(invoices.getUserId());
        }
        if (!StringUtil.isNullOrEmpty(invoices.getUserName())){
            criteria.andUserNameEqualTo(invoices.getUserName());
        }
        if (!StringUtil.isNullOrEmpty(invoices.getInvoiceNumber())){
            criteria.andInvoiceNumberEqualTo(invoices.getInvoiceNumber());
        }
        if (!StringUtil.isNullOrEmpty(invoices.getInvoiceDate())){
            criteria.andInvoiceDateEqualTo(invoices.getInvoiceDate());
        }
        if (!StringUtil.isNullOrEmpty(invoices.getTotalAmount())){
            criteria.andTotalAmountEqualTo(invoices.getTotalAmount());
        }
        if (!StringUtil.isNullOrEmpty(invoices.getDescription())){
            criteria.andDescriptionEqualTo(invoices.getDescription());
        }
        List<Invoices> invoicesList = invoicesMapper.selectByExample(example);
        return invoicesList;
    }
}
